package com.reder.practice.common.handler;

import com.reder.practice.common.dto.ServerResponse;
import com.reder.practice.common.enums.state.CommonState;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常捕获器
 *
 * @author Fish
 * <p>Email: fishinlove@163.com</p>
 * <p>created by 2019/09/23 14:50:07</p>
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class ServerExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ServerResponse handleException(Exception e) {

        // 记录日志
        log.error("ServerExceptionHandler 异常！", e);
        return ServerResponse.response(CommonState.SERVER_INTERNAL_ERROR);
    }
}


